
Page({
  data: {
    inputValue: '',
    showError: false,
    isSubmitting: false,
    submittedData: ''
  },

  onInputChange: function(e) {
    const value = e.detail.value;
    this.setData({
      inputValue: value,
      showError: false
    });
  },

  onTextareaBlur: function(e) {
    const value = e.detail.value;
    if (value && value.trim()) {
      this.setData({
        inputValue: value.trim()
      });
    }
  },

  // 提交
  async onSubmit() {
    const value = this.data.inputValue.trim();
    if (!value) {
      this.setData({
        showError: true
      });
      // wx.showToast({
      //   title: '请输入内容',
      //   icon: 'none'
      // });
      return;
    }
    this.setData({
      isSubmitting: true
    });
    var data=await global.$api.post({
      url:'api/userInfo/addAppUserFeedback',
      data:{
        content:this.data.inputValue
      }
    })
    if(data.code==200){
      this.setData({
        isSubmitting: false,
        submittedData: value,
        showError: false
      });
      // 清空输入框
      this.setData({
        inputValue: ''
      });
      wx.showToast({
        title: '提交成功',
        icon: 'success'
      });
      setTimeout(() => {
        wx.navigateBack({
          delta: 1,
        })
      }, 800)
    }else{
      wx.showToast({
        title: data.message,
        icon:'none'
      })
    }

  }
})
